package com.example.lib_mvp;

import android.annotation.SuppressLint;
import android.content.Context;
import android.telephony.TelephonyManager;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PhoneInfoUtils {


    @SuppressLint("MissingPermission")
    public static String getPhoneNumber(Context context) {
        TelephonyManager telephonyManager = (TelephonyManager)
                context.getSystemService(Context.TELEPHONY_SERVICE);
        return telephonyManager.getLine1Number();
    }


    public static String getPhoneNumberMasked(String phoneNumber) {
        StringBuilder sb = new StringBuilder(phoneNumber);
        sb.replace(3, 7, "****");
        return sb.toString();
    }

    //校验通过返回true，否则返回false
    public static boolean isMobile(String mobile) {
        String str = mobile;
        String pattern = "^(13[0-9]|15[012356789]|17[013678]|18[0-9]|14[57]|19[89]|166)[0-9]{8}";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(str);
        return m.matches();
    }
}
